package com.liyongzhen.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;

public class JwtUtils {
    private static String signKey="liyongzhen2";
    private static long expire= 43200000L;

    /*
    * 生成Jwt令牌
    * */
    public static String generateJwt(Map<String,Object> claims){
        String Jwt = Jwts.builder()
                .addClaims(claims)
                .signWith(SignatureAlgorithm.HS256,signKey)
                .setExpiration(new Date(System.currentTimeMillis()+expire))
                .compact();
        return Jwt;
    }

    /*
    * 解析Jwt令牌*/
    public static Claims parseJWT(String Jwt){
        Claims claims = Jwts.parser()
                .setSigningKey(signKey)
                .parseClaimsJws(Jwt)
                .getBody();
        return claims;
    }
}
